#!/usr/bin/env node

const http=require('http'),
      fs=require('fs');


function genPage(){
  let html = fs.readFileSync('./index.html');
  return html;
}
function genData(){
  let data1=require('./data.js');
  let data2=data1.filter(function(ele){
    return ele.movieRange!=='暂无评分';
  });
  data2.sort((a,b)=>b.movieRange-a.movieRange);
  let data3=JSON.stringify(data2);
  
  return data3;
}

http.createServer((req,res)=>{
  if(req.url === '/'){
    res.statusCode = 200;
    res.setHeader('Content-Type', 'text/html');
    res.end(genPage());
  }
  if(req.url==='/getlist'){
    res.end(genData());
  
  }
}).listen(8080);

